package com.juli.v2xdemo.tcp.tcp_impl;

import com.cz.basetool.CodeTool;
import com.example.tcpmaster.AbsSocketTransceiver;
import com.example.tcpmaster.AbsTcpManager;
import com.example.tcpmaster.TcpClient;

import java.net.Socket;

/**
 * Created by lianxiang on 2017/9/7.
 */

public class TcpManager extends AbsTcpManager {
    volatile private static  TcpManager instance; //禁止指令重新排序

    private TcpManager() {
    }

    @Override
    public boolean sendMsg(String str) {
        return sendMsg(CodeTool.HexToByteArr(str));
    }

    public static TcpManager getInstance() {
        if (instance == null) {
            synchronized (TcpManager.class) {
                if (instance == null) {
                    instance = new TcpManager();
                }
            }
        }
        return instance;
    }


    @Override
    public AbsSocketTransceiver getSocketTransceiver(TcpClient tcpClient, Socket socket) {
        return new SocketTransceiver(tcpClient,socket);
    }
}
